var vm = new Vue({
    el: '#app',
    data:function(){
        return{
            pagename:"进度",
            common_fn:null,
            userinfo:null,
            loading:false,
            mainTable_maxHeight:0,
            search:{
                lotno:'',
                name:'',
                productno:''
            },
            productionschedule:true,
            process:false,
            mesproductionschedule_data:[],
            tempItem_mesproductionschedule : null,
            process_data : [],
            //组件信息
            differentComponentDialog:null,
            differentComponentItem:null
        }
    },
    methods:{
        returnpage:function(){
            if(this.process){
                this.productionschedule = true;
                this.process = false;
            }
        },
        load_mesproductionschedule:function(){
            var self = this;
            var param = {
                sql:"select * from View_AllMesProductionScheduleProgress where MesProductionSchedule__State = 3",
                appName:"mes"
            }
            if(self.search.lotno!=''){
                param.sql+=" and MesProductionSchedule__LotNo like '%"+ self.search.lotno +"'";
            }
            if(self.search.name!=''){
                param.sql+=" and MesProductionSchedule__Name like '%"+ self.search.name +"'";
            }
            if(self.search.productno!=''){
                param.sql+=" and MesProductionSchedule__ProductNo like '%"+ self.search.productno +"'";
            }
            self.loading = true;
            self.common_fn.sqlFn(param,function(response){
                if (response.resFlag == 0) {
                    self.mesproductionschedule_data = [];
                    for (var i = response.result.length-1; i>=0; i--) {
                        if(Number(response.result[i].properties.mesproductionschedule__lotnum) == 0){ response.result.splice(i,1);continue }
                        response.result[i].properties['progress'] = (Number(response.result[i].properties.mesproductionschedule__sumprdavailquantity) / Number(response.result[i].properties.mesproductionschedule__lotnum) * 100).toFixed(2);
                        response.result[i].properties['progressColor'] = response.result[i].properties.progress==100?'success':'';
                        self.mesproductionschedule_data = response.result;
                    }
                    self.productionschedule = true;
                    self.process = false;
                } else {
                    notify(response.errMsg,'error')
                }
                self.loading = false;
            })
        },
        load_process:function(list){
            var self = this;
            self.tempItem_mesproductionschedule = list;
            var param = {
                sql:"select objid,name,OrderQuantity ,RealQuantity,(select Sum(ISNULL(RepairQuantity,0)) from MES_QACHECKITEM where PROCESS_OBJID = sf.PROCESS_OBJID and PRODUCT_OBJID = sf.PRODUCT_OBJID) as RejectQuantity,(select ISNULL(PREPAREHOUR ,0)+ ISNULL(MANUFACTORYHOUR ,0) from  qcp_process where objid = sf.process_objid) as ManufactoryHour,(select min(reporttime) from MES_REPORTSHEET where state=5 and SEMIFINISHED_OBJID = sf.objid) as reporttime from [MES_SEMIFINISHED] sf where sf.product_objid = "+list.properties.mesproductionschedule__objid,
                appName:"mes"
            }
            self.loading = true;
            self.common_fn.sqlFn(param,function(response){
                if (response.resFlag == 0) {
                    for (var i = response.result.length-1; i >=0; i--) {
                        if(Number(response.result[i].properties.orderquantity) == 0){ response.result.splice(i,1);continue }
                        response.result[i].properties['progress'] = (Number(response.result[i].properties.realquantity) / Number(response.result[i].properties.orderquantity) * 100).toFixed(2);
                        response.result[i].properties['progressColor'] = response.result[i].properties.progress==100?'success':'';
                        response.result[i].properties['url'] = "./progressDetail.html?productObjid="+self.tempItem_mesproductionschedule.properties.mesproductionschedule__objid+"&&semiFinishedObjid="+response.result[i].properties.objid;
                    }
                    self.process_data = response.result;
                    self.productionschedule = false;
                    self.process = true;
                } else {
                    notify(response.errMsg,'error')
                }
                self.loading = false;
            })
        }
    },
    created:function(){
        this.mainTable_maxHeight = window.screen.availHeight-120-80;
    },
    mounted:function(){
        var self = this;
        self.common_fn = new common_fn();
        self.common_fn.init(function(){
            self.common_fn.UserInfo(function(response){
                if(response.user == null){
                    window.location.href = '../login.html?redirect=./report/progress.html';
                }
                self.userinfo = response;
                self.common_fn.CheckFunction(self.userinfo,'mes','mes','Progress','','','progress',function(){})
                self.load_mesproductionschedule();
            })
        });
    }
})
